Crate glib[−][src]
Expand description
Rust GLib and GObject bindings
This library contains bindings to GLib and GObject types and APIs as well as common building blocks used in both handmade and machine generated bindings to GTK and other GLib-based libraries.
It is the foundation for higher level libraries with uniform Rusty (safe and strongly typed) APIs. It avoids exposing GLib-specific data types where possible and is not meant to provide comprehensive GLib bindings, which would often amount to duplicating the Rust Standard Library or other utility crates.
GLib 2.48 is the lowest supported version for the underlying library.
Dynamic typing
Most types in the GLib family have Type
identifiers.
Their corresponding Rust types implement the StaticType
trait.
A dynamically typed Value
can carry values of any StaticType
.
Variant
s can carry values of StaticVariantType
.
Errors
Errors are represented by Error
, which can
carry values from various error domains such as
FileError
.
Objects
Each class and interface has a corresponding smart pointer struct
representing an instance of that type (e.g. Object
for GObject
or
gtk::Widget
for GtkWidget
). They are reference counted and feature
interior mutability similarly to Rust’s Rc<RefCell<T>>
idiom.
Consequently, cloning objects is cheap and their methods never require
mutable borrows. Two smart pointers are equal if they point to the same
object.
The root of the object hierarchy is Object
.
Inheritance and subtyping is denoted with the IsA
marker trait. The Cast
trait enables upcasting
and downcasting.
Interfaces and non-leaf classes also have corresponding traits (e.g.
ObjectExt
or gtk::WidgetExt
), which are blanketly implemented for all
their subtypes.
You can create new subclasses of Object
or other object types. Look at
the module’s documentation for further details and a code example.
Under the hood
GLib-based libraries largely operate on pointers to various boxed or
reference counted structures so the bindings have to implement corresponding
smart pointers (wrappers), which encapsulate resource management and safety
checks. Such wrappers are defined via the
wrapper
macro, which uses abstractions
defined in the wrapper
, boxed
,
shared
and object
modules.
The translate
module defines and partly implements
conversions between high level Rust types (including the aforementioned
wrappers) and their FFI counterparts.
Re-exports
pub use ffi;
pub use gobject_ffi;
pub use self::closure::Closure;
pub use self::error::BoolError;
pub use self::error::Error;
pub use self::object::Cast;
pub use self::object::Class;
pub use self::object::InitiallyUnowned;
pub use self::object::Interface;
pub use self::object::IsA;
pub use self::object::Object;
pub use self::object::ObjectExt;
pub use self::object::ObjectType;
pub use self::object::SendWeakRef;
pub use self::object::WeakRef;
pub use self::signal::signal_handler_block;
pub use self::signal::signal_handler_disconnect;
pub use self::signal::signal_handler_unblock;
pub use self::signal::signal_stop_emission_by_name;
pub use self::signal::SignalHandlerId;
pub use self::types::ILong;
pub use self::types::StaticType;
pub use self::types::Type;
pub use self::types::ULong;
pub use self::value::BoxedValue;
pub use self::value::SendValue;
pub use self::value::ToSendValue;
pub use self::value::ToValue;
pub use self::value::Value;
pub use self::variant::FromVariant;
pub use self::variant::StaticVariantType;
pub use self::variant::ToVariant;
pub use self::variant::Variant;
pub use self::char::*;
pub use self::source::*;
pub use self::send_unique::SendUnique;
pub use self::send_unique::SendUniqueCell;
Modules
IMPL
Boxed wrapper implementation.
Error
binding and helper trait.
IMPL
Object wrapper implementation and Object
binding.
Traits and essential types intended for blanket imports.
IMPL
Shared (reference counted) wrapper implementation.
IMPL
Low level signal support.
Module containing infrastructure for subclassing GObject
s and registering boxed types.
Translation between GLib/GLib-based FFI types and their Rust counterparts.
Runtime type information.
Value
binding and helper traits.
Variant
binding and helper traits.
IMPL
The wrapper!
macro and miscellaneous wrapper traits.
Macros
Generic error used for functions that fail without any further information
Macro for passing variables as strong or weak references into a closure.
log_macros
A macro which behaves exactly as log::debug!
except that it sets the
current log target to the contents of a G_LOG_DOMAIN
constant (and fails
to build if not defined).
log_macros
A macro which behaves exactly as log::error!
except that it sets the
current log target to the contents of a G_LOG_DOMAIN
constant (and fails
to build if not defined).
Macro used to log using GLib logging system. It uses g_log.
Macro used to print error messages. It uses g_printerr.
Wrapper implementations for Boxed types. See wrapper!
.
ObjectType implementations for Object types. See wrapper!
.
Wrapper implementations for shared types. See wrapper!
.
log_macros
A macro which behaves exactly as log::info!
except that it sets the
current log target to the contents of a G_LOG_DOMAIN
constant (and fails
to build if not defined).
log_macros
A macro which behaves exactly as log::trace!
except that it sets the
current log target to the contents of a G_LOG_DOMAIN
constant (and fails
to build if not defined).
log_macros
A macro which behaves exactly as log::warn!
except that it sets the
current log target to the contents of a G_LOG_DOMAIN
constant (and fails
to build if not defined).
Defines a wrapper type and implements the appropriate traits.
Structs
A shared immutable byte slice (the equivalent of Rc<[u8]>
).
A CollationKey
allows ordering strings using the linguistically correct rules for the current locale.
Representation of an enum
for dynamically, at runtime, querying the values of the enum and
using them.
Representation of a single enum value of an EnumClass
.
v2_66
A FilenameCollationKey
allows ordering file names using the linguistically correct rules for the current locale.
Compared to CollationKey
, filename collation keys take into consideration dots and other characters
commonly found in file names.
Builder for conveniently setting/unsetting flags and returning a Value
.
Representation of a flags
for dynamically, at runtime, querying the values of the enum and
using them
Representation of a single flags value of a FlagsClass
.
An implementation of a log
compatible
logger which logs over glib logging facilities.
A Receiver
that can be attached to a main context to receive items from its corresponding
Sender
or SyncSender
.
A Sender
that can be used to send items to the corresponding main context receiver.
Represents a Future
around a glib::Source
. The future will
be resolved once the source has provided a value
Represents a Stream
around a glib::Source
. The stream will
be provide all values that are provided by the source
A mutable text buffer that grows automatically.
A SyncSender
that can be used to send items to the corresponding main context receiver.
v2_66
v2_66
v2_66
VariantDict
is a mutable key/value store where the keys are always
strings and the values are Variant
s.
Iterator over items in a variant.
Iterator over items in a variant of type as
.
Describes Variant
types.
Describes Variant
types.
Enums
Enumeration of the possible domain handling behaviours for a
GlibLogger
.
Enumeration of the possible formatting behaviours for a
GlibLogger
.
v2_66
Constants
This is the log domain used by the clone!
macro. If you want to use a custom
logger (it prints to stdout by default), you can set your own logger using the corresponding
log
functions.
Statics
Traits
Functions
Obtain the character set for the current locale.
Create a Future
that will resolve once the child process with the given pid exits
Create a Future
that will resolve once the child process with the given pid exits
v2_62
Create a Stream
that will provide a value every given number of milliseconds.
Create a Stream
that will provide a value every given number of seconds.
Create a Stream
that will provide a value every given number of seconds.
Create a Stream
that will provide a value every given number of milliseconds.
To set back the default print handler, use the log_unset_default_handler
function.
To set the default print handler, use the log_set_default_handler
function.
v2_64
Same as get_prgname()
.
Provides a glib log handler which routes all logging messages to the
log crate
.
To set back the default print handler, use the unset_print_handler
function.
To set back the default print handler, use the unset_printerr_handler
function.
Same as set_prgname()
.
v2_58
and non-WindowsCreate a Future
that will resolve after the given number of milliseconds.
Create a Future
that will resolve after the given number of seconds.
Create a Future
that will resolve after the given number of seconds.
Create a Future
that will resolve after the given number of milliseconds.
Create a Future
that will resolve once the given UNIX signal is raised
Create a Future
that will resolve once the given UNIX signal is raised
Create a Stream
that will provide a value whenever the given UNIX signal is raised
Create a Stream
that will provide a value whenever the given UNIX signal is raised
To set the default print handler, use the set_print_handler
function.
To set the default print handler, use the set_printerr_handler
function.
v2_52
v2_52
Type Definitions
Attribute Macros
Attribute macro for defining flags using the bitflags
crate.
This macro will also define a GFlags::type_
function and
the glib::Value
traits.
Macro for boilerplate of ObjectInterface
implementations.
Macro for boilerplate of ObjectSubclass
implementations.
Derive Macros
Macro for deriving implementations of glib::clone::Downgrade
and
glib::clone::Upgrade
traits and a weak type.
Derive macro for defining a BoxedType
::type_
function and
the glib::Value
traits.
Derive macro for defining a GLib error domain and its associated
ErrorDomain
trait.
Derive macro for defining a SharedType
::get_type
function and
the glib::Value
traits.